package docmanager.operation.roles;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import docmanager.business.objects.OperacionDB;
import docmanager.business.objects.Rol;
import docmanager.db.ConnectionPool;

import bf.operation.Operation;
import bf.operation.OperationException;

public class OpModificarRol1 extends Operation {

	@Override
	public Map execute(HttpServletRequest request) throws OperationException {
		Map m = new HashMap();
		
		try {
			int id = Integer.parseInt(request.getParameter("id"));
			Connection conn = ConnectionPool.getConnection();
			Rol rol = new Rol(conn, id);
			rol.cargarOperaciones();
			m.put("rol", rol);
			m.put("operaciones",OperacionDB.obtenerTodasOperaciones(conn));

			ConnectionPool.closeConn(conn);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new OperationException();
		}
		return m;
	}

	@Override
	public String getReturnURL() {
		// TODO Auto-generated method stub
		return "Roles/AMRoles.jsp";
	}

}
